package org.jsola.hr.query;

import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;
import org.jsola.core.query.BaseQuery;
import org.jsola.orm.filter.Order;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

import static org.jsola.hr.example.SalaryBillSendExample.E_AUTO_CHECK_HOURS;
import static org.jsola.hr.example.SalaryBillSendExample.E_AUTO_CHECK_UNIT;
import static org.jsola.hr.example.SalaryBillSendExample.E_CHECK_COUNT;
import static org.jsola.hr.example.SalaryBillSendExample.E_COMPANY_ID;
import static org.jsola.hr.example.SalaryBillSendExample.E_FEEDBACK_COUNT;
import static org.jsola.hr.example.SalaryBillSendExample.E_READ_COUNT;
import static org.jsola.hr.example.SalaryBillSendExample.E_SEND_BY;
import static org.jsola.hr.example.SalaryBillSendExample.E_SEND_COUNT;
import static org.jsola.hr.example.SalaryBillSendExample.E_SEND_NAME;
import static org.jsola.hr.example.SalaryBillSendExample.E_SEND_TIME_END;
import static org.jsola.hr.example.SalaryBillSendExample.E_SEND_TIME_START;
import static org.jsola.hr.example.SalaryBillSendExample.E_SEND_TYPE;
import static org.jsola.hr.example.SalaryBillSendExample.E_SHOW_EMPTY_VALUE;
import static org.jsola.hr.example.SalaryBillSendExample.E_TABLE_ID;
import static org.jsola.hr.example.SalaryBillSendExample.E_WITHDRAWN_COUNT;
import static org.jsola.hr.example.SalaryBillSendExample.E_WITHDRAW_STATUS;
import static org.jsola.hr.example.SalaryBillSendExample.N_AUTO_CHECK_HOURS;
import static org.jsola.hr.example.SalaryBillSendExample.N_AUTO_CHECK_UNIT;
import static org.jsola.hr.example.SalaryBillSendExample.N_CHECK_COUNT;
import static org.jsola.hr.example.SalaryBillSendExample.N_COMPANY_ID;
import static org.jsola.hr.example.SalaryBillSendExample.N_FEEDBACK_COUNT;
import static org.jsola.hr.example.SalaryBillSendExample.N_READ_COUNT;
import static org.jsola.hr.example.SalaryBillSendExample.N_SEND_BY;
import static org.jsola.hr.example.SalaryBillSendExample.N_SEND_COUNT;
import static org.jsola.hr.example.SalaryBillSendExample.N_SEND_NAME;
import static org.jsola.hr.example.SalaryBillSendExample.N_SEND_TIME_END;
import static org.jsola.hr.example.SalaryBillSendExample.N_SEND_TIME_START;
import static org.jsola.hr.example.SalaryBillSendExample.N_SEND_TYPE;
import static org.jsola.hr.example.SalaryBillSendExample.N_SHOW_EMPTY_VALUE;
import static org.jsola.hr.example.SalaryBillSendExample.N_TABLE_ID;
import static org.jsola.hr.example.SalaryBillSendExample.N_WITHDRAWN_COUNT;
import static org.jsola.hr.example.SalaryBillSendExample.N_WITHDRAW_STATUS;

/**
 * 工资条发放信息
 *
 * @author zhr
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class SalaryBillSendQuery extends BaseQuery {

    private static final long serialVersionUID = 1L;

    @ApiParam(value = N_TABLE_ID, example = E_TABLE_ID)
    @Length(max = 32)
    private String tableId;

    @ApiParam(value = N_SEND_TYPE, example = E_SEND_TYPE)
    private Integer sendType;

    @ApiParam(value = N_AUTO_CHECK_HOURS, example = E_AUTO_CHECK_HOURS)
    private Integer autoCheckHours;

    @ApiParam(value = N_AUTO_CHECK_UNIT, example = E_AUTO_CHECK_UNIT)
    private Integer autoCheckUnit;

    @ApiParam(value = N_SHOW_EMPTY_VALUE, example = E_SHOW_EMPTY_VALUE)
    private Boolean showEmptyValue;

    @ApiParam(value = N_SEND_NAME, example = E_SEND_NAME)
    @Length(max = 255)
    private String sendName;

    @ApiParam(value = N_SEND_BY, example = E_SEND_BY)
    @Length(max = 255)
    private String sendBy;

    /**
     * 发放时间查询范围
     */
    @ApiParam(value = N_SEND_TIME_START, example = E_SEND_TIME_START)
    private Date sendTimeStart;
    @ApiParam(value = N_SEND_TIME_END, example = E_SEND_TIME_END)
    private Date sendTimeEnd;


    @ApiParam(value = N_SEND_COUNT, example = E_SEND_COUNT)
    private Integer sendCount;

    @ApiParam(value = N_READ_COUNT, example = E_READ_COUNT)
    private Integer readCount;

    @ApiParam(value = N_CHECK_COUNT, example = E_CHECK_COUNT)
    private Integer checkCount;

    @ApiParam(value = N_FEEDBACK_COUNT, example = E_FEEDBACK_COUNT)
    private Integer feedbackCount;

    @ApiParam(value = N_WITHDRAWN_COUNT, example = E_WITHDRAWN_COUNT)
    private Integer withdrawnCount;

    @ApiParam(value = N_WITHDRAW_STATUS, example = E_WITHDRAW_STATUS)
    private Boolean withdrawStatus;

    @ApiParam(value = N_COMPANY_ID, example = E_COMPANY_ID)
    @Length(max = 32)
    private String companyId;



    @ApiParam(value = "排序字段", allowMultiple=true, type="Order" ,example = "\"orders\": [{\"property\": \"userName\",\"desc\": false}]")
    private List<Order> orders;

    /**
     * 每页的条数
     */
    @ApiParam(value = "分页参数，每页的条数", example = "20")
    @Max(value = 1000, message = "pageSize不能大于1000")
    private Integer pageSize = 20;

    /**
     * 当前第几页
     */
    @ApiParam(value = "分页参数，第几页", example = "1")
    @Min(value = 1, message = "pageNo不能小于1")
    private Integer pageNo = 1;



    /**
     * 添加排序
     * @param propertyName 属性名
     * @param desc 是否降序
     * @return this
     */
    public SalaryBillSendQuery addOrder(String propertyName, boolean desc) {
        if (CollectionUtils.isEmpty(this.orders)) {
            this.orders = new ArrayList<>();
        }
        this.orders.add(new Order(propertyName,desc));
        return this;
    }

}

